//
//  MyCollectionTableViewCell.m
//  ExcellentHome
//
//  Created by Andy on 15/8/10.
//  Copyright (c) 2015年 陈区. All rights reserved.
//

#import "MyCollectionTableViewCell.h"

@implementation MyCollectionTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {

        self.picImageView = [[UIImageView alloc] init];
        UIImage* image = [UIImage imageWithContentsOfFile:SEGPicName(@"pic_default_300_300")];
        self.picImageView.backgroundColor = [UIColor lightGrayColor];
        self.picImageView.contentMode = UIViewContentModeScaleAspectFill;
        [self.picImageView.layer setMasksToBounds:YES];
        [self.picImageView setImage:image];
        [self addSubview:self.picImageView];
        
        self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, LYScreenWidth() - 110, 60)];
        [self.contentLabel setFont:[UIFont systemFontOfSize:16]];
        self.contentLabel.textColor = kColor_1;
        [self.contentLabel setText:nil];
        [self addSubview:self.contentLabel];
        
    }

    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];

    self.picImageView.frame = CGRectMake(CGRectGetWidth(self.bounds) - 85, (CGRectGetHeight(self.bounds) - 60) / 2, 75, 60);
}

- (void)onRequestData:(id)data
{
    @try {
        //初始化
        [self.picImageView setImage:nil];

        [self.contentLabel setText:nil];

        NSDictionary* dict = data;

        self.contentLabel.numberOfLines = 3;

        [self.contentLabel setText:[dict valueForKey:@"collectName"]];

        NSString *picurl=[dict valueForKey:@"collectUrl"];
        
        if ([SEGUtils isBlankString:picurl]) {
            self.picImageView.hidden=YES;
            self.contentLabel.frame=CGRectMake(20, 10, LYScreenWidth() - 40, 60);
        }else{
            self.picImageView.hidden=NO;
            self.contentLabel.frame=CGRectMake(20, 10, LYScreenWidth() - 110, 60);
        }
        
        [self.picImageView setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@", kClientImageRootURL, picurl]]
            placeholderImage:[UIImage imageWithContentsOfFile:SEGPicName(@"pic_default_300_300")]
            options:SDWebImageLowPriority];
    }
    @catch (NSException* exception) {

    }
    @finally {
    
    }
}

@end
